package com.mifengs.mall.util;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;

import com.mifengs.mall.Constant;
import com.mifengs.mall.entity.AdvertBean;
import com.mifengs.mall.event.MainEvent;
import com.mifengs.mall.ui.login.NewRegisterActivity;
import com.mifengs.mall.ui.login.RegisterStepOneActivity;
import com.mifengs.mall.ui.web.CommonWebActivity;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by lynn on 2017/11/7.
 *
 */

public class ToIntentUtil {
    public static void toCommonIntent(String  url, Context mContext){
        Intent intent;
        if(url.startsWith(Constant.REGISTER_URL)){
            Uri uri = Uri.parse(url);
            String shareId = uri.getQueryParameter("shareId");
            intent = new Intent(mContext, NewRegisterActivity.class);
            intent.putExtra("shareId",shareId);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            mContext.startActivity(intent);
        }else if(url.startsWith(Constant.H5_CLASSIFT)){
            EventBus.getDefault().post(new MainEvent(MainEvent.TOCATEGORY));
            if(mContext instanceof CommonWebActivity){
                ((CommonWebActivity) mContext).finish();
            }
        }else if(url.startsWith(Constant.H5_MY)){
            EventBus.getDefault().post(new MainEvent(MainEvent.TOMY));
            if(mContext instanceof CommonWebActivity){
                ((CommonWebActivity) mContext).finish();
            }
        } else {
            intent = new Intent(mContext, CommonWebActivity.class);
            intent.putExtra(CommonWebActivity.ExtraWebTitle,"");
            intent.putExtra(CommonWebActivity.ExtraWebPath,url);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            mContext.startActivity(intent);
        }
    }
}
